<#include "/include/macros.ftl">
<@header></@header>
<div class="clearfix"></div>
<div class="row">
    <div class="col-md-12 col-sm-12 col-xs-12">
        <@breadcrumb>
            <ol class="breadcrumb">
                <li><a href="/">首页</a></li>
                <li class="active">用户组管理</li>
            </ol>
        </@breadcrumb>
        <div class="x_panel">
            <div class="x_content">
                <div class="<#--table-responsive-->">
                    <div class="btn-group hidden-xs" id="toolbar">
                        <@shiro.hasPermission name="group:add">
                        <button id="btn_add" type="button" class="btn btn-default" title="新增用户组">
                            <i class="fa fa-plus"></i> 新增用户组
                        </button>
                        </@shiro.hasPermission>
                       <#-- <@shiro.hasPermission name="group:batchDelete">
                            <button id="btn_delete_ids" type="button" class="btn btn-default" title="禁用选中">
                                <i class="fa fa-trash-o"></i> 批量禁用
                            </button>
                        </@shiro.hasPermission>-->
                    </div>
                    <table id="tablelist">
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<!--弹框-->
<div class="modal fade bs-example-modal-sm" id="selectRole" tabindex="-1" role="dialog" aria-labelledby="selectRoleLabel">
    <div class="modal-dialog modal-sm" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="selectRoleLabel">分配用户</h4>
            </div>
            <div class="modal-body">
                <form id="boxRoleForm">
                    <div class="zTreeDemoBackground left">
                        <ul id="treeDemo" class="ztree"></ul>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal"><i class="fa fa-close"> 关闭</i></button>
            </div>
        </div>
    </div>
</div>
<@addOrUpdateMOdal defaultTitle="添加用户组">
    <input type="hidden" name="id">
    <div class="item form-group">
        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">用户组名 <span class="required">*</span></label>
        <div class="col-md-6 col-sm-6 col-xs-12">
            <input type="text" class="form-control col-md-7 col-xs-12" name="name" id="name" required="required" placeholder="请输入组名"/>
        </div>
    </div>
    <div class="item form-group">
        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="remark">备注 </label>
        <div class="col-md-6 col-sm-6 col-xs-12">
            <input type="text" class="form-control col-md-7 col-xs-12" id="remark" name="remark" placeholder="请输入备注"/>
        </div>
    </div>
</@addOrUpdateMOdal>
<@footer>
    <script>
        /**
         * 操作按钮
         * @param code
         * @param row
         * @param index
         * @returns {string}
         */
        function operateFormatter(code, row, index) {
            var currentGroupId = '${group.id}';
            var trGroupId = row.id;
            var operateBtn = [
                '<@shiro.hasPermission name="group:edit"><a class="btn btn-xs btn-primary btn-update" data-id="' + trGroupId + '"><i class="fa fa-edit"></i>编辑</a></@shiro.hasPermission>',
            ];
            if (currentGroupId != trGroupId) {
                /*operateBtn.push('<@shiro.hasPermission name="group:remove"><a class="btn btn-xs btn-danger btn-remove" data-id=' + trGroupId + '"><i class="fa fa-trash-o"></i>删除</a></@shiro.hasPermission>');*/
                operateBtn.push('<@shiro.hasPermission name="usergroup:add"><a class="btn btn-xs btn-info btn-allot" data-id="' + trGroupId + '"><i class="fa fa-circle-thin"></i>分配用户</a></@shiro.hasPermission>')
            }
            return operateBtn.join('');
        }

        $(function () {
            var options = {
                url: "/groups/list",
                getInfoUrl: "/groups/get/{id}",
                updateUrl: "/groups/edit",
                removeUrl: "/groups/remove",
                createUrl: "/groups/add",
                columns: [
                    {
                        checkbox: true
                    }, {
                        field: 'name',
                        title: '用户组名',
                        editable: true,
                    }, {
                        field: 'remark',
                        title: '备注',
                        editable: true
                    }, {
                        field: 'statusEnum',
                        title: '状态',
                        editable: false
                    }, {
                        field: 'operate',
                        title: '操作',
                        formatter: operateFormatter //自定义方法，添加操作按钮
                    }
                ],
                modalName: "用户"
            };
            //1.初始化Table
            $.tableUtil.init(options);
            //2.初始化Button的点击事件
            $.buttonUtil.init(options);

            /* 添加用户 */
            $('#tablelist').on('click', '.btn-allot', function () {
                console.log("添加用户");
                var $this = $(this);
                var groupId = $this.attr("data-id");
                window.open("/user_group/"+groupId);
            });
        });
    </script>
</@footer>